﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using EHTSaleManager.Code.BLL;
using EHTSaleManager.Code.Entity;
using EHTSaleManager.Code.Utility;
using System.Web.Security;

namespace EHTSaleManager
{
    public partial class IndexCustomerHistoryOfOrder : System.Web.UI.Page
    {
        string CustomerID = "";
        private Int32 pageIndex = 1;
        private Int32 pageSize = 5;
        private Int32 totalRecord;
        protected void Page_Load(object sender, EventArgs e)
        {
            MembershipUser theUser = Membership.GetUser(HttpContext.Current.User.Identity.Name);
            CustomerID = theUser.ProviderUserKey.ToString();

            Int32 orderSate = HangSo.ORDER_STATE_APPENDING;

            try
            {
                orderSate = Int32.Parse(Request.QueryString["OrderState"].ToString());
            }
            catch (Exception ex)
            {
                orderSate = HangSo.ORDER_STATE_APPENDING;
            }

            try
            {
                pageIndex = Int32.Parse(Request.QueryString["PageIndex"].ToString());
            }
            catch (Exception)
            {
                pageIndex = 1;
            }

            pageSize = this.PaggingControl1.PageSize;

            if (!Page.IsPostBack)
            {
                Int32 totalOrderAppending = 0;
                Int32 totalOrder = 0;
                OrderProvider.GetParametersOfOrderByCustomerID(out totalOrderAppending, out totalOrder, CustomerID);
                this.hlOrderAppending.Text = "Orders Appending (" + totalOrderAppending.ToString() + ")";
                this.hlOrderAll.Text = "All Orders (" + totalOrder.ToString() + ")";

                LoadDataOrders(orderSate, CustomerID);
            }
        }
        private void LoadDataOrders(Int32 OrderState, String CustomerID)
        {
            DataSet dsOrders = OrderProvider.GetOrdersByCustomerIDAndOrderState(pageIndex, pageSize, out totalRecord, CustomerID, OrderState);
            this.rpOrders.DataSource = dsOrders;
            this.rpOrders.DataBind();

            this.PaggingControl1.PageURL = "IndexCustomerHistoryOfOrder.aspx?OrderState=" + OrderState.ToString();
            this.PaggingControl1.TotalRecord = totalRecord;
            this.PaggingControl1.PagingSize = pageSize;
        }
    }
}